package com.gp.learn.ssm.base.core.security.model;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
@Data
public class OpenUser implements UserDetails {

    /**
     * 账户Id
     */
    private Long accountId;

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 登录名
     */
    private String username;

    /**
     * 密码
     */
    private String password;

    /**
     * 是否未锁定
     */
    private boolean accountNonLocked;

    /**
     * 是否未过期
     */
    private boolean accountNonExpired;

    /**
     * 是否启用
     */
    private boolean enabled;

    /**
     * 密码是否未过期
     */
    private boolean credentialsNonExpired;

    /**
     * 用户权限
     */
    private Collection<? extends GrantedAuthority> authorities;

    public OpenUser(Long accountId, Long userId, String username, String password, boolean accountNonLocked, boolean accountNonExpired, boolean enabled, Collection<? extends GrantedAuthority> authorities) {
        this.accountId = accountId;
        this.userId = userId;
        this.username = username;
        this.password = password;
        this.accountNonLocked = accountNonLocked;
        this.accountNonExpired = accountNonExpired;
        this.enabled = enabled;
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public String getUsername() {
        return this.username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return this.accountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.accountNonLocked;
    }

    @Override
    public boolean isEnabled() {
        return this.enabled;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

}
